<?php

namespace App\Http\Middleware;


use Closure;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Arr;
use Overtrue\Socialite\User as SocialiteUser;

class OfficialTest
{

    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        $user = [
            "openid" => "oa0JauK4rqUJYX7iIRsDDTD99OxA",
            "nickname" => "庄新华",
            "sex" => 1,
            "language" => "zh_CN",
            "city" => "长春",
            "province" => "吉林",
            "country" => "中国",
            "headimgurl" => "http://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLmNcfbdkfBs2lvicaFGHiaNvDJcoYicf1p9JWf2wlOq9ictIS7v1yswPYtBxKLOAAxq54DrOgbIXib4gw/132",
            "privilege" => []
        ];
        $user = new SocialiteUser([
            'id' => Arr::get($user, 'openid'),
            'name' => Arr::get($user, 'nickname'),
            'nickname' => Arr::get($user, 'nickname'),
            'avatar' => Arr::get($user, 'headimgurl'),
            'headimgurl' => Arr::get($user, 'headimgurl'),
            'email' => null,
            'original' => [],
            'provider' => 'WeChat',
        ]);

        session(['wechat.oauth_user.default' => $user]); // 同理，`default` 可以更换为您对应的其它配置名

        return $next($request);
    }

}
